package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import lombok.extern.slf4j.XSlf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类用于创建AliOSSUTtil对象
 *
 */
@Configuration
@Slf4j
public class OssConfiguration {

    @Bean //为什么用Bean，因为这个方法被调用不到，用bean交给spring容器处理
    @ConditionalOnMissingBean //以防被多次创建
    public AliOssUtil getAliOssUtil(AliOssProperties aliOssProperties) {
        log.info("开始创建ali云文件上传工具类对象");
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());

    }
}
